<?php
	/**
	* New User Management
	* For Pray Online
	* Show list of user in our system, that in lock status. 
	* If last_login = 0: this is new registration user, and needed approve 
	* If last_login > 0: this is locked user.
	* 
	* Note: Permission set on openidmodule, because, loginmodule does not have permission
	*/

	if (!defined('EXPONENT')) exit('');
	
	$max_item=15;
	// check permission first
	$loc=null;
	$loc->mod="openidmodule"; // because, loginmodule does not have permission, so we set permission on openidmodule
	$loc->src="";
	$loc->int="";
	if (exponent_permissions_check("view_userprofile",$loc) ||
	exponent_permissions_check("administrate",$loc))
	{
		exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);
		$i18n = exponent_lang_loadFile('modules/loginmodule/actions/login.php');

		if (!defined('SYS_USERS')) require_once('subsystems/users.php');

		exponent_users_includeProfileExtensions();
		exponent_users_clearDeletedExtensions();
		global $db;

		// Get a list of all active Profile Extenions.
		$exts = $db->selectObjects('profileextension');
		// Initialize the Sorting Subsystem, if this hasn't previously been done.
		if (!defined('SYS_SORTING')) require_once(BASE.'subsystems/sorting.php');
		// Sort the active extension objects by their rank,
		usort($exts,'exponent_sorting_byRankAscending');

		// page split
		// cal how many posts
		$count_post = $db->countObjects('user');
		$pages=floor($count_post / $max_item);
		if ($count_post % $max_item != 0)
			$pages++;

		// get page
		$page=1;
		if (isset($_REQUEST['page']))  $page=intval($_REQUEST['page']);
		if (($page<1) || ($page>$pages)) $page=1;
		$start_pos=($page-1)*$max_item;
		// end of pagination

		$users=$db->selectObjects("user","1 ORDER BY is_locked DESC, id DESC LIMIT {$start_pos},{$max_item}");

		foreach ($users as $ku=>$vu)
		{
			foreach ($exts as $ext) {
				// Update this part of the User's profile.
				$vu = call_user_func(array($ext->extension,'getProfile'),$vu);
			}
			$vu->reg_on=date("d/m/Y",$vu->created_on)."<br>".date("h:i:s",$vu->created_on);
		}

		// generate email form
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		$form->meta("action","newuser_sendmail");
		$form->meta("module","loginmodule");
		$form->meta("user_id","-1");
		$form->register('content','Nội dung liên hệ',new texteditorcontrol("",3,82));
		$form->register('submit','',new buttongroupcontrol('Đồng ý'));

		//eDebug($profile);exit();
		$template = $template = new template("loginmodule","_show_newuser_manage");
		$template->assign("users",$users);
		$template->assign("page",$page);
		$template->assign("pages",$pages);
		$template->assign("start_pos",$start_pos);
		$template->assign("form_html",$form->toHTML());
		$template->output();

	}
	else
	{
		echo SITE_403_HTML;
	}
?>
